<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>JAXB Architecture - The Java EE 5 Tutorial</title>
<meta name="robots" content="index,follow">
<meta name="robots" content="index,follow">
<meta name="date" content="2008-10-01">
<link rel="stylesheet" type="text/css" href="css/default.css">
<link rel="stylesheet" type="text/css" href="css/ipg.css">
<link rel="stylesheet" type="text/css" href="css/j5eetutorial.css">
</head>

<body>

<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody>
   <tr valign="top">
      <td><p class="toc level1"><a href="docinfo.html">Document Information</a></p>
<p class="toc level1 tocsp"><a href="gexaf.html">Preface</a></p>
<p class="toc level1 tocsp"><a href="gfirp.html">Part&nbsp;I&nbsp;Introduction</a></p>
<p class="toc level2"><a href="bnaaw.html">1.&nbsp;&nbsp;Overview</a></p>
<p class="toc level2"><a href="gfiud.html">2.&nbsp;&nbsp;Using the Tutorial Examples</a></p>
<p class="toc level1 tocsp"><a href="bnadp.html">Part&nbsp;II&nbsp;The Web Tier</a></p>
<p class="toc level2"><a href="bnadr.html">3.&nbsp;&nbsp;Getting Started with Web Applications</a></p>
<p class="toc level2"><a href="bnafd.html">4.&nbsp;&nbsp;Java Servlet Technology</a></p>
<p class="toc level2"><a href="bnagx.html">5.&nbsp;&nbsp;JavaServer Pages Technology</a></p>
<p class="toc level2"><a href="bnajo.html">6.&nbsp;&nbsp;JavaServer Pages Documents</a></p>
<p class="toc level2"><a href="bnakc.html">7.&nbsp;&nbsp;JavaServer Pages Standard Tag Library</a></p>
<p class="toc level2"><a href="bnalj.html">8.&nbsp;&nbsp;Custom Tags in JSP Pages</a></p>
<p class="toc level2"><a href="bnaon.html">9.&nbsp;&nbsp;Scripting in JSP Pages</a></p>
<p class="toc level2"><a href="bnaph.html">10.&nbsp;&nbsp;JavaServer Faces Technology</a></p>
<p class="toc level2"><a href="bnaqz.html">11.&nbsp;&nbsp;Using JavaServer Faces Technology in JSP Pages</a></p>
<p class="toc level2"><a href="bnatx.html">12.&nbsp;&nbsp;Developing with JavaServer Faces Technology</a></p>
<p class="toc level2"><a href="bnavg.html">13.&nbsp;&nbsp;Creating Custom UI Components</a></p>
<p class="toc level2"><a href="bnawo.html">14.&nbsp;&nbsp;Configuring JavaServer Faces Applications</a></p>
<p class="toc level2"><a href="bnaxu.html">15.&nbsp;&nbsp;Internationalizing and Localizing Web Applications</a></p>
<p class="toc level1 tocsp"><a href="bnayk.html">Part&nbsp;III&nbsp;Web Services</a></p>
<p class="toc level2"><a href="bnayl.html">16.&nbsp;&nbsp;Building Web Services with JAX-WS</a></p>
<p class="toc level2"><a href="bnazf.html">17.&nbsp;&nbsp;Binding between XML Schema and Java Classes</a></p>
<div class="onpage">
<p class="toc level3"><a href="">JAXB Architecture</a></p>
<p class="toc level4"><a href="#bnazh">Architectural Overview</a></p>
<p class="toc level4"><a href="#bnazj">The JAXB Binding Process</a></p>
<p class="toc level4"><a href="#bnazl">More about Unmarshalling</a></p>
<p class="toc level4"><a href="#bnazm">More about Marshalling</a></p>
<p class="toc level4"><a href="#bnazn">More about Validation</a></p>
</div>
<p class="toc level3 tocsp"><a href="bnazo.html">Representing XML Content</a></p>
<p class="toc level4"><a href="bnazo.html#bnazp">Java Representation of XML Schema</a></p>
<p class="toc level3 tocsp"><a href="bnazq.html">Binding XML Schemas</a></p>
<p class="toc level4"><a href="bnazq.html#bnazr">Simple Type Definitions</a></p>
<p class="toc level4"><a href="bnazq.html#bnazs">Default Data Type Bindings</a></p>
<p class="toc level5"><a href="bnazq.html#bnazt">Schema-to-Java Mapping</a></p>
<p class="toc level5"><a href="bnazq.html#bnazv"><tt>JAXBElement</tt> Object</a></p>
<p class="toc level5"><a href="bnazq.html#bnazw">Java-to-Schema Mapping</a></p>
<p class="toc level3 tocsp"><a href="bnazy.html">Customizing Generated Classes and Java Program Elements</a></p>
<p class="toc level4"><a href="bnazy.html#bnazz">Schema-to-Java</a></p>
<p class="toc level4"><a href="bnazy.html#bnbaa">Java-to-Schema</a></p>
<p class="toc level3 tocsp"><a href="bnbah.html">JAXB Examples</a></p>
<p class="toc level4"><a href="bnbah.html#bnbal">JAXB Compiler Options</a></p>
<p class="toc level4"><a href="bnbah.html#bnban">JAXB Schema Generator Option</a></p>
<p class="toc level4"><a href="bnbah.html#bnbao">About the Schema-to-Java Bindings</a></p>
<p class="toc level4"><a href="bnbah.html#bnbar">Schema-Derived JAXB Classes</a></p>
<p class="toc level5"><a href="bnbah.html#bnbas"><tt>Comment</tt> Class</a></p>
<p class="toc level5"><a href="bnbah.html#bnbat"><tt>Items</tt> Class</a></p>
<p class="toc level5"><a href="bnbah.html#bnbau"><tt>ObjectFactory</tt> Class</a></p>
<p class="toc level5"><a href="bnbah.html#bnbav"><tt>PurchaseOrder</tt> Class</a></p>
<p class="toc level5"><a href="bnbah.html#bnbaw"><tt>PurchaseOrderType</tt> Class</a></p>
<p class="toc level5"><a href="bnbah.html#bnbax"><tt>USAddress</tt> Class</a></p>
<p class="toc level3 tocsp"><a href="bnbay.html">Basic JAXB Examples</a></p>
<p class="toc level4"><a href="bnbay.html#bnbaz">Modify Marshal Example</a></p>
<p class="toc level5"><a href="bnbay.html#bnbba">Building and Running the Modify Marshal Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbay.html#bnbbb">Building and Running the Modify Marshal Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbay.html#bnbbc">Unmarshal Validate Example</a></p>
<p class="toc level5"><a href="bnbay.html#bnbbd">Building and Running the Unmarshal Validate Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbay.html#bnbbe">Building and Running the Unmarshal Validate Example Using Ant</a></p>
<p class="toc level3 tocsp"><a href="bnbbf.html">Customizing JAXB Bindings</a></p>
<p class="toc level4"><a href="bnbbf.html#bnbbg">Why Customize?</a></p>
<p class="toc level4"><a href="bnbbf.html#bnbbh">Customization Overview</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbbi">Inline and External Customizations</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbbo">Scope, Inheritance, and Precedence</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbbq">Customization Syntax</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbby">Customization Namespace Prefix</a></p>
<p class="toc level4 tocsp"><a href="bnbbf.html#bnbbz">Customize Inline Example</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbca">Building and Running the Customize Inline Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcb">Building and Running the Customize Inline Example Using Ant</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcc">Customized Schema</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcd">Global Binding Declarations</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbce">Schema Binding Declarations</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcf">Class Binding Declarations</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcg">Property Binding Declarations</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbch"><tt>MyDatatypeConverter</tt> Class</a></p>
<p class="toc level4 tocsp"><a href="bnbbf.html#bnbci">Datatype Converter Example</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcj">Building and Running the Datatype Converter Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbck">Building and Running the Datatype Converter Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbbf.html#bnbcl">Binding Declaration Files</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcm">JAXB Version, Namespace, and Schema Attributes</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcq">Global and Schema Binding Declarations</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcr">Class Declarations</a></p>
<p class="toc level4 tocsp"><a href="bnbbf.html#bnbcs">External Customize Example</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbct">Building and Running the External Customize Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbbf.html#bnbcu">Building and Running the External Customize Example Using Ant</a></p>
<p class="toc level3 tocsp"><a href="bnbcv.html">Java-to-Schema Examples</a></p>
<p class="toc level4"><a href="bnbcv.html#bnbcw">Create Marshal Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbcx">Building and Running the Create Marshal Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbcy">Building and Running the Create Marshal Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbcv.html#bnbcz">XmlAccessorOrder Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbda">Using the <tt>@XmlAccessorOrder</tt> Annotation to Define Schema Element Ordering</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdb">Using the <tt>@XmlType</tt> Annotation to Define Schema Element Ordering</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdc">Schema Content Ordering in the Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdd">Building and Running the XmlAccessorOrder Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbde">Building and Running the XmlAccessorOrder Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbcv.html#bnbdf">XmlAdapter Field Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdg">Building and Running the XmlAdapter Field Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdh">Building and Running the XmlAdapter Field Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbcv.html#bnbdi">XmlAttribute Field Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdj">Building and Running the XmlAttribute Field Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdk">Building and Running the XmlAttribute Field Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbcv.html#bnbdl">XmlRootElement Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdm">Building and Running the XmlRootElement Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdn">Building and Running the XmlRootElement Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbcv.html#bnbdo">XmlSchemaType Class Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdp">Building and Running the XmlSchemaType Class Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdq">Building and Running the XmlSchemaType Class Example Using Ant</a></p>
<p class="toc level4 tocsp"><a href="bnbcv.html#bnbdr">XmlType Example</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbds">Building and Running the XmlType Example Using NetBeans IDE</a></p>
<p class="toc level5"><a href="bnbcv.html#bnbdt">Building and Running the XmlType Example Using Ant</a></p>
<p class="toc level3 tocsp"><a href="bnbdu.html">Further Information about JAXB</a></p>
<p class="toc level2 tocsp"><a href="bnbdv.html">18.&nbsp;&nbsp;Streaming API for XML</a></p>
<p class="toc level2"><a href="bnbhf.html">19.&nbsp;&nbsp;SOAP with Attachments API for Java</a></p>
<p class="toc level1 tocsp"><a href="bnblr.html">Part&nbsp;IV&nbsp;Enterprise Beans</a></p>
<p class="toc level2"><a href="bnbls.html">20.&nbsp;&nbsp;Enterprise Beans</a></p>
<p class="toc level2"><a href="bnbnb.html">21.&nbsp;&nbsp;Getting Started with Enterprise Beans</a></p>
<p class="toc level2"><a href="bnboc.html">22.&nbsp;&nbsp;Session Bean Examples</a></p>
<p class="toc level2"><a href="bnbpk.html">23.&nbsp;&nbsp;A Message-Driven Bean Example</a></p>
<p class="toc level1 tocsp"><a href="bnbpy.html">Part&nbsp;V&nbsp;Persistence</a></p>
<p class="toc level2"><a href="bnbpz.html">24.&nbsp;&nbsp;Introduction to the Java Persistence API</a></p>
<p class="toc level2"><a href="bnbrl.html">25.&nbsp;&nbsp;Persistence in the Web Tier</a></p>
<p class="toc level2"><a href="bnbrs.html">26.&nbsp;&nbsp;Persistence in the EJB Tier</a></p>
<p class="toc level2"><a href="bnbtg.html">27.&nbsp;&nbsp;The Java Persistence Query Language</a></p>
<p class="toc level1 tocsp"><a href="bnbwi.html">Part&nbsp;VI&nbsp;Services</a></p>
<p class="toc level2"><a href="bnbwj.html">28.&nbsp;&nbsp;Introduction to Security in the Java EE Platform</a></p>
<p class="toc level2"><a href="bnbyk.html">29.&nbsp;&nbsp;Securing Java EE Applications</a></p>
<p class="toc level2"><a href="bncas.html">30.&nbsp;&nbsp;Securing Web Applications</a></p>
<p class="toc level2"><a href="bncdq.html">31.&nbsp;&nbsp;The Java Message Service API</a></p>
<p class="toc level2"><a href="bncgv.html">32.&nbsp;&nbsp;Java EE Examples Using the JMS API</a></p>
<p class="toc level2"><a href="bncih.html">33.&nbsp;&nbsp;Transactions</a></p>
<p class="toc level2"><a href="bncjh.html">34.&nbsp;&nbsp;Resource Connections</a></p>
<p class="toc level2"><a href="bncjx.html">35.&nbsp;&nbsp;Connector Architecture</a></p>
<p class="toc level1 tocsp"><a href="bnckn.html">Part&nbsp;VII&nbsp;Case Studies</a></p>
<p class="toc level2"><a href="bncko.html">36.&nbsp;&nbsp;The Coffee Break Application</a></p>
<p class="toc level2"><a href="bnclz.html">37.&nbsp;&nbsp;The Duke's Bank Application</a></p>
<p class="toc level1 tocsp"><a href="gexbq.html">Part&nbsp;VIII&nbsp;Appendixes</a></p>
<p class="toc level2"><a href="bncno.html">A.&nbsp;&nbsp;Java Encoding Schemes</a></p>
<p class="toc level2"><a href="bncnq.html">B.&nbsp;&nbsp;Preparation for Java EE Certification Exams</a></p>
<p class="toc level2"><a href="bncnt.html">C.&nbsp;&nbsp;About the Authors</a></p>
<p class="toc level1 tocsp"><a href="idx-1.html">Index</a></p>
</td>
      <td width="10px">&nbsp;</td>
      <td width="705px">
         <div class="header">
             <div class="header-links-top">
                 <a href="http://java.sun.com">java.sun.com</a> |
                 <a href="http://docs.sun.com/">docs.sun.com</a><br>
             </div> 
             <img src="graphics/tutorialBanner.gif" width="704" height="120" alt="The Java&trade; EE 5 Tutorial"/>
             <div class="header-links">
	         <a href="index.html">Home</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/download.html">Download</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/doc/JavaEETutorial.pdf">PDF</a> |
                 <a href="http://java.sun.com/javaee/5/docs/api/index.html">API</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/faq.html">FAQ</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/search.html">Search</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/sendusmail.html">Feedback</a> |
                 <a href="http://java.sun.com/javaee/5/docs/tutorial/information/history.html">History</a>
             </div>
             <div class="navigation">
                 <a href="bnazf.html"><img style="padding-right: 3px" src="graphics/leftButton.gif" border="0"></a>
                 <a href="sjsaseej2eet.html"><img style="padding-right: 3px" src="graphics/upButton.gif" border="0"></a>
                 <a href="bnazo.html"><img style="padding-left: 3px" src="graphics/rightButton.gif" border="0"></a>
             </div>
         </div>

	 <div class="maincontent">      	 
             

<a name="bnazg"></a><h3>JAXB Architecture</h3>
<a name="indexterm-1691"></a><p>This section describes the components and interactions in the JAXB processing model.</p>

<a name="bnazh"></a><h4>Architectural Overview</h4>
<p><a href="#bnazi">Figure&nbsp;17-1</a> shows the components that make up a JAXB implementation.</p><a name="bnazi"></a><h6>Figure&nbsp;17-1 JAXB Architectural Overview</h6><img src="figures/jaxb-overview.gif" alt="Diagram of JAXB architecture, showing Schema on left, Schema Generator and Schema Compiler in the middle, and Application Code on the right."></img><p>A JAXB implementation consists of the following architectural components:</p>
<ul><li><p><a name="indexterm-1692"></a><b>Schema compiler</b>: Binds a source schema to a set of schema-derived program elements. The binding is described by an XML-based binding language.</p></li>
<li><p><a name="indexterm-1693"></a><b>Schema generator</b>: Maps a set of existing program elements to a derived schema. The mapping is described by program annotations.</p></li>
<li><p><a name="indexterm-1694"></a><b>Binding runtime framework</b>: Provides unmarshalling (reading) and marshalling (writing) operations for accessing, manipulating, and validating XML content using either schema-derived or existing program elements.</p></li></ul>


<a name="bnazj"></a><h4>The JAXB Binding Process</h4>
<a name="indexterm-1695"></a><p><a href="#bnazk">Figure&nbsp;17-2</a> shows what occurs during the JAXB binding process.</p><a name="bnazk"></a><h6>Figure&nbsp;17-2 Steps in the JAXB Binding Process</h6><img src="figures/jaxb-dataBindingProcess.gif" alt="Diagram of the JAXB Binding Process: Schema, JAXB mapped classes, Document, and Objects"></img><p>The general steps in the JAXB data binding process are:</p>
<ol><li><p><b>Generate classes</b>: An XML schema is used as input to the JAXB binding compiler to generate JAXB classes based on that schema.</p></li>
<li><p><b>Compile classes</b>: All of the generated classes, source files, and application code must be compiled.</p></li>
<li><p><b>Unmarshal</b>: XML documents written according to the constraints in the source schema are unmarshalled by the JAXB binding framework. Note that JAXB also supports unmarshalling XML data from sources other than files/documents, such as DOM nodes, string buffers, SAX Sources, and so forth.</p></li>
<li><p><b>Generate content tree</b>: The unmarshalling process generates a content tree of data objects instantiated from the generated JAXB classes; this content tree represents the structure and content of the source XML documents.</p></li>
<li><p><b>Validate (optional)</b>: The unmarshalling process optionally involves validation of the source XML documents before generating the content tree. Note that if you modify the content tree in Step 6, below, you can also use the JAXB Validate operation to validate the changes before marshalling the content back to an XML document.</p></li>
<li><p><b>Process content</b>: The client application can modify the XML data represented by the Java content tree by means of interfaces generated by the binding compiler.</p></li>
<li><p><b>Marshal</b>: The processed content tree is marshalled out to one or more XML output documents. The content may be validated before marshalling.</p></li></ol>


<a name="bnazl"></a><h4>More about Unmarshalling</h4>
<a name="indexterm-1696"></a><p>Unmarshalling provides a client application the ability to convert XML data into JAXB-derived
Java objects.</p>

<a name="bnazm"></a><h4>More about Marshalling</h4>
<a name="indexterm-1697"></a><p>Marshalling provides a client application the ability to convert a JAXB-derived Java object
tree back into XML data.</p><p>By default, the <tt>Marshaller</tt> uses UTF-8 encoding when generating XML data.</p><p>Client applications are not required to validate the Java content tree before marshalling.
There is also no requirement that the Java content tree be valid with
respect to its original schema to marshal it back into XML data.</p>

<a name="bnazn"></a><h4>More about Validation</h4>
<a name="indexterm-1698"></a><p>Validation is the process of verifying that an XML document meets all the
constraints expressed in the schema. JAXB 1.0 provided validation at unmarshal time and
also enabled on-demand validation on a JAXB content tree. JAXB 2.0 only allows
validation at unmarshal and marshal time. A web service processing model is to
be lax in reading in data and strict on writing it out.
To meet that model, validation was added to marshal time so one could
confirm that they did not invalidate the XML document when modifying the document
in JAXB form.</p>
         </div>
         <div class="navigation">
             <a href="bnazf.html"><img style="padding-right: 3px" src="graphics/leftButton.gif" border="0"></a>
             <a href="sjsaseej2eet.html"><img style="padding-right: 3px" src="graphics/upButton.gif" border="0"></a>
             <a href="bnazo.html"><img style="padding-left: 3px" src="graphics/rightButton.gif" border="0"></a>
         </div>

         <div class="copyright">
      	    <p>The material in The Java&trade; EE 5 Tutorial is <a href='docinfo.html'>copyright</a>-protected and may not be published in other works without express written permission from Sun Microsystems.</p>
      	 </div>

      </td>
   </tr>
</tbody>
</table>
</body>
</html>

